#include<stdio.h>

// utility function for input
int read_array(int *A){
    int n;
    printf("Enter the length of the array: ");
    scanf("%d",&n);
    printf("Enter the array seperated by white spaces: ");
    for(int i = 0;i<n;i++)scanf("%d",A+i);fflush(stdin);
    return n;
}


void print_array(int*A,int n){
    for(int i = 0;i<n;i++)printf("%d%c",A[i],i==(n-1)?'\n':' ');
}

// 合并有序表A和B，存到C
void merge(const int* A,int m,const int *B,int n,int* C){
    int i,j;
    i = j = 0;
    while(i<m&&j<n)if(A[i]<B[j])*C++=A[i++];else *C++=B[j++];
    if(i==m)while(j<n)*(C++)=B[j++];else while(i<m)*(C++)=A[i++];
}

int main(){
    int A[1024];
    int m = read_array(A);
    int B[1024];
    int n = read_array(B);
    int C[2048];
    int k = m+n;
    merge(A,m,B,n,C);
    print_array(C,k);
    return 0;
}
